require('../less/login.less')
require('../fonts/iconfont.css')
document.ready(function(){
    // 获取元素
    const registered=document.querySelector("#registered");
    const logging=document.querySelector("#logging");
    const account=document.querySelector("#uname");
    const password=document.querySelector("#pow")
    const messain=document.querySelector("#messain")
    console.log(messain);
    // 注册账号的点击事件
    registered.addEventListener("click",function(){
        location.href='register.html'
    })

    // // 验证手机号
    // if(until.isPhone.test(account.value)){
    //     until.Registrat("fail","手机号不合法")
    // }
    // 登录验证
    logging.addEventListener("click",function(){

        // 验证手机号
        if(until.isPhone(account.value)){
            until.Registrat("fail","手机号不合法")

        }else{
            // 发请求核对数据
             $http.post('/users/login', {account: account.value, password: password.value },function(res){
            if(res.status === 0){
                until.Registrat('success','登录成功');
                localStorage.setItem("userId",res.data.user.userId);
                setTimeout(function(){
                    location.href = './index.html'
                },2000)
            }else{
                until.Registrat('fail',res.msg)
                
            }
        })}
        
       


    })

    
})